﻿using System.Globalization;

namespace KinonekoSoftware.Foundation.UI.Converters
{
#if AVALONIA

    using Avalonia.Data.Converters;
    
#else
    using System.Windows.Data;
    
#endif
    
    public class StringToIntConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var v = value?.ToString();
            var val = int.TryParse(v, out var n) ? n : 0;
            return val;
        }
        
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        { 
            return value?.ToString();
        }
    }
}